<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ include file="/common/_taglibs.jsp"%>
<%@ include file="/common/_meta.jsp"%>
<title>添加资源-资源管理</title>
<meta name="keywords" content="cms-simple CMS后台管理系统">
<meta name="description" content="cms-simple CMS后台管理系统">
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-admin-add" action="${ctx }/sys/addResource" method="post" onsubmit="return onCheck();">
	<input type="hidden" name="id" value="${resource.id }"/>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>资源名称：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="${resource.name }" placeholder="" id="name" name="name">
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>资源描述：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="${resource.description }" placeholder="" id="description" name="description">
		</div>
	</div>
	<div class="row cl">
		<input type="hidden" id="pids" name="pids" />
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>资源关系：</label>
		<div class="formControls col-xs-8 col-sm-9 zTreeDemoBackground left">
			<ul id="treeDemo" class="ztree"></ul>
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>资源代码：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="${resource.code }" placeholder="" id="code" name="code">
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>资源类型：</label>
		<div class="formControls col-xs-5"> <span class="select-box">
			<select class="select" size="1" name="type">
				<c:if test="${resource.type == null}">
					<option value="" selected>==请选择==</option>
					<option value="1">菜单</option>
					<option value="2">方法</option>
				</c:if>
				<c:if test="${resource.type == 1}">
					<option value="">==请选择==</option>
					<option value="1" selected>菜单</option>
					<option value="2">方法</option>
				</c:if>
				<c:if test="${resource.type == 2}">
					<option value="">==请选择==</option>
					<option value="1">菜单</option>
					<option value="2" selected>方法</option>
				</c:if>
			</select>
			</span> </div>
		<div class="col-xs-5"> </div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>资源地址：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="${resource.url }" placeholder="" id="url" name="url">
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>资源排序(<strong>${resource.maxSort }</strong>)：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="${resource.sort }" placeholder="" id="sort" name="sort">
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span><a href="http://www.h-ui.net/Hui-3.7-Hui-iconfont.shtml" target="_blank">资源图标：</a></label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="${resource.icon }" placeholder="" id="icon" name="icon">
		</div>
	</div>
	<div class="row cl">
		<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
			<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
		</div>
	</div>
	</form>
</article>
<script type="text/javascript" src="${ctx }/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${ctx }/lib/jquery/1.9.1/jquery.form.js"></script> 
<script type="text/javascript" src="${ctx }/lib/layer/2.1/layer.js"></script>
<script type="text/javascript" src="${ctx }/lib/icheck/jquery.icheck.min.js"></script> 
<script type="text/javascript" src="${ctx }/lib/jquery.validation/1.14.0/jquery.validate.min.js"></script>
<script type="text/javascript" src="${ctx }/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="${ctx }/lib/jquery.validation/1.14.0/messages_zh.min.js"></script>
<script type="text/javascript" src="${ctx }/static/h-ui/js/H-ui.js"></script>
<script type="text/javascript" src="${ctx }/static/h-ui.admin/js/H-ui.admin.js"></script> 
<script type="text/javascript" src="${ctx }/lib/zTree/v3/js/jquery.ztree.core-3.5.min.js"></script>
<script type="text/javascript" src="${ctx }/lib/zTree/v3/js/jquery.ztree.excheck-3.5.js"></script>
<!--请在下方写此页面业务相关的脚本--> 
<script type="text/javascript">

$(function(){
	
	$(".selected").on("change", function(){
		console.info($(this));
		var pid = $(this).children('option:selected').val();
		if(pid != ""){
			$.ajax({
				type: "GET",
				url: "${ctx }/sys/loadParentResource?pid="+pid,
				success: function(rootResourceList){
					var html = "";
					if(rootResourceList == null){
						return;
					}
					html += '<div class="formControls col-xs-3">';
					html += '<span class="select-box">';
						html += '<select class="select selected" size="1" name="pids">';
						html += '<option value="" selected>请选择</option>';
						for(var i=0; i<rootResourceList.length; i++){
							html += '<option value="'+rootResourceList[i]["id"]+'">'+rootResourceList[i]["name"]+'</option>';
						}
						html += '</select>';
					html += '</span></div>';
					$("#selectedRootResource").append(html);
				},
			});
		};
	});
	
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#form-admin-add").validate({
		rules:{
			loginCode:{
				required:true,
				minlength:6,
				maxlength:20
			},
			resourceName:{
				required:true,
				minlength:4,
				maxlength:10
			},
			password:{
				required:true,
			},
			password2:{
				required:true,
				equalTo: "#password"
			}
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit();
			var index = parent.layer.getFrameIndex(window.name);
			parent.$('.btn-refresh').click();
			parent.layer.close(index);
		}
	});
});

var setting = {
	check: {
		enable: true,
		chkStyle: "radio",
		radioType: "all"
	},
	data: {
		simpleData: {
			enable: true,
			idKey: "id",
			pIdKey: "pid",
			rootPId: 0
		}
	}
};

var zNodes = ${rootResourceList };
$(document).ready(function(){
	$.fn.zTree.init($("#treeDemo"), setting, zNodes);
});

function onCheck(){
	var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
	var nodes = treeObj.getCheckedNodes(true);
	var length = nodes.length;
	var pids = new Array();
	if(nodes != null && length > 0){
		for(var i=0; i<length; i++){
			pids.push(nodes[i]["id"]);
		};
	};
	$("#pids").val(pids);
};
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
